import React from 'react';
import InputItem from '../../../components/InputItem';
import {Descriptions, Input,InputNumber, message,Modal, Radio} from 'antd';
import QCProjectController from '@/services/QCProject/QCProjectController';
const {TextArea}= Input
const {confirm} = Modal
class ResultUpload extends React.Component {
    constructor(props) {
        super(props);
        this.state = { datas:{},rowData:props.rowData,checkItem:[] };
    }
    componentDidMount(){
        this.props.onRef(this)
        let checkItem = []
        this.props.rowData.checkItem.split("，").forEach(item=>{
            checkItem.push({key:item,value:'完成'})
        })
        this.setState({
            checkItem
        })
    }
    handleChange=(datas)=>{
        this.setState({datas})
    }
    submit=()=>{
        let {datas,rowData,checkItem}=this.state
        let that = this
        if(!datas.resultActivity){
            message.error('请输入主要活动')
            return;
        }
        if(!datas.resultSelfEvaluation){  
            message.error('请输入效果自评')
            return;
        }
        if(!datas.resultEconomic){
            message.error('请输入经济效益')
            return;
        }
        let params = {
            ...datas,projectCode:rowData.projectCode,checkItem:JSON.stringify(checkItem)
        }
        confirm({
            title:'提示',
            content:'确定要提交吗？',
            onOk(){
                QCProjectController.resultSubmit(params).then(r=>{
                    if(r&&r.data===1){
                        message.success('提交成功')
                        that.props.onCancel()
                    }
                })
            }
        })
        

    }
    radioChange=(index,e)=>{
        let {checkItem} = this.state
        checkItem[index].value = e.target.value
        this.setState({
            checkItem
        })
    }
    render() {
        const {datas,checkItem} = this.state
        const columns=[
            {name:'主要活动',keyName:'resultActivity',valueType:'text',style:{width:600},value:datas.resultActivity},
            {name:'效果自评',keyName:'resultSelfEvaluation',valueType:'text',style:{width:600},value:datas.resultSelfEvaluation},
            {name:'经济效益',keyName:'resultEconomic',valueType:'textArea',style:{width:600},value:datas.resultEconomic},
        ]
        return (
            <div>
                <InputItem columns={columns} onChange={this.handleChange}/>
                <Descriptions title={"自主检查项"}></Descriptions>
                {checkItem.map((item,index)=>{
                    return<div style={{margin:10}}>
                    <strong>{item.key}：</strong>
                    <Radio.Group onChange={this.radioChange.bind(this,index)} key={item.key}>
                        <Radio value={'完成'} key={'1'}>完成</Radio>
                        <Radio value={'未完成'} key={'2'}>未完成</Radio>
                    </Radio.Group></div>
                })}
            </div>
        );
    }
}

export default ResultUpload;